package com.zsrt.java.day20161229.xww;

import java.util.Scanner;

public class Calculate {

	public static void main(String[] args) {
		login();
	}
	public static int add(int a,int b,int c){
		int add=a+b+c;
		return add;
	}
	public static int sub(int a,int b,int c){
		int sub=a-b-c;
		return sub;
	}
	public static int mul(int a,int b,int c){
		int mul=a*b*c;
		return mul;
	}
	public static int div(int a,int b,int c){
		int div=a/b/c;
		return div;
	}
	/**
	 * 登陆
	 */
	public static void login(){
		Scanner sc=new Scanner(System.in);
		System.out.println("请输入用户名：");
		String username=sc.next();
		System.out.println("密码：");
		String password=sc.next();
		if("zz".equals(username)&&"zz".equals(password)){
			System.out.println("成功");
			cal();
		}else{
			System.out.println("失败");
			sc.close();
		}
	}
	/**
	 * 运算加减乘除
	 */
	public static void cal(){
		Scanner sc = new Scanner(System.in);
		System.out.println("输入一个三位数");
		int shu=sc.nextInt();
		if(100<=shu||shu<=999){
			int a=shu/100;
			int b=shu/10%10;
			int c=shu%10;
			int fuhao=c%4;
			if(1==fuhao){
				int jieguo=add(a, b, c);
				System.out.println("值为："+jieguo);
			}else if(2==fuhao){
				int jieguo=sub(a, b, c);
				System.out.println("值为："+jieguo);
			}else if(3==fuhao){
				int jieguo=mul(a, b, c);
				System.out.println("值为："+jieguo);
			}else if(4==fuhao){
				int jieguo=div(a, b, c);
				System.out.println("值为："+jieguo);
			}else{
				System.out.println("该数不符合条件不做加减乘除");
			}
				yn();
				sc.close();
		}
		
	}
	/**
	 * 判断是否继续
	 */
	public static void yn(){
		Scanner sc=new Scanner(System.in);
		System.out.println("game over,are you sure to play again? y/n");
		String yn=sc.next();
		if("y".equals(yn)){
			cal();
		}if("n".equals(yn)){
		  sc.close();
		}
	}

}
